package com.lion.seaman.worker.thread;


import com.lion.seaman.orm.bin.SpringContext;
import com.lion.seaman.orm.bin.SystemConfig;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class ThreadPoolManager {

    SystemConfig systemConfig;

    private ThreadPoolManager() {
        systemConfig = SpringContext.getBean(SystemConfig.class);
    }

    public static ThreadPoolManager MANAGER = new ThreadPoolManager();

    ScheduledExecutorService taskExecutor;


    public ScheduledExecutorService getTaskExecutor() {
        if (taskExecutor == null) {
            taskExecutor = Executors.newScheduledThreadPool(systemConfig.get("job.threadPool.maxCount", 10));
        }
        return taskExecutor;
    }

    public static void close() {
        MANAGER.taskExecutor.shutdown();
    }
}
